<?php
namespace app\index\controller;
use think\Cookie;
use \think\Session;
use think\Controller;
use \think\Db;
class Adm extends Controller{
	public function index(){

	}
	//显示期刊揭秘那
    public function magazine(){
        return view();
    }
    //显示管理员界面
	public function admin(){

		$level=Session::get('user');  
		if(!empty($level)){
			$this->assign('username',$level->getName());
            if ($level->getLevel() == 0) {
                if(Cookie::has('news')==null){
                    Cookie::forever('news','0');
                }else{
                    if(cookie('news')==0){
                        Cookie::forever('news','1');
                    }
                }
                $this->assign('news',cookie('news'));

                return $this -> fetch();
            } else if($level->getLevel() == 1){
                $this->redirect('/index/Sta/staff');
            }else{
                $this->redirect('/index/Pre/preview');
            }
    	}else{
    		$this->redirect('/');
    	}

	}
	//管理员退出接口
	public function userExit(){
		Session::clear();
		return Session::has('user');
	}
	//显示用户管理界面
	public function manageUser(){
        return $this->fetch();
    }
    //显示图书管理界面
    public function manageMaterial(){
        return $this->fetch();
    }
    public function manageCompany(){
        return view();
    }
    //返回用户总数的接口
    public function getPageNum(){
        return db('user')->count();
    }
    //显示用户新增界面
    public function insertUser(){
        return view();
    }
    public function changeCompany(){
        $company_id = input('company_id');

        $result= Db::table('company')
            ->where('company_id','=',$company_id)
            ->find();

        $this->assign('company_name',$result['company_name']);
        $this->assign('company_logo',$result['company_logo']);
        $this->assign('company_url',$result['company_url']);
        $this->assign('company_id',$company_id);

        return view();
    }
}